<template>
	<view>
		<qf-image-cropper :width="1200" :height="900" fileType="jpg" @crop="handleCrop"></qf-image-cropper>
	</view>
</template>

<script>
	import QfImageCropper from '@/uni_modules/qf-image-cropper/components/qf-image-cropper/qf-image-cropper.vue';
	import config from "../../config";
	import { getToken } from '@/utils/auth'
	export default {
		components: {
			QfImageCropper
		},
		methods: {
			handleCrop(e) {
				// console.log(e)
				const fileUpload = config.baseUrl + '/xcx/common/upload';
				uni.uploadFile({
					url: fileUpload,
					filePath: e.tempFilePath,
					name: 'file',
					header: {
						"token": getToken(),
					},
					// 成功函数
					success: (res) => {
						console.log('上传成功');
						let uploaddata = JSON.parse(res.data)
						let data = uploaddata.data
						let pages = getCurrentPages();  //获取所有页面栈实例列表
						let prevPage = pages[ pages.length - 2 ];  //上一页页面实例
						prevPage.$vm.form.url = data.ossId;   //修改上一页data里面的参数值
						prevPage.$vm.urlPath = data.url
						uni.navigateBack()
					},
					// 失败提示用户重新上传
					fail: error => {
						console.log('失败', error);
					}
				})
			}
 		}
	}
</script>

<style>

</style>
